package patterns.singleton;

/**
 * Created by lenovo on 2016/11/22 0022.
 * 懒汉式、加线程同步锁，支持多线程，但是效率低
 */
public class LazybonesSafe {
    //声明创建对象实例
    private static LazybonesSafe instance;
    //私有化构造函数
    private LazybonesSafe(){}
    //对外提供对象获取的公开接口，加上synchronized来同步线程锁
    public static synchronized LazybonesSafe getInstance(){
        if (instance==null){
            instance = new LazybonesSafe();
        }
        return instance;
    }

    //随便写一个方法，用于测试demo
    public void show(){
        System.out.println("懒汉模式，线程安全式");
    }
}
